package hhm.android.my

import android.content.Context
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.resource.bitmap.CircleCrop
import com.bumptech.glide.request.RequestOptions
import hhm.android.base.adapter.HBaseAdapter
import hhm.android.library.utils.GlideUtils
import hhm.android.library.utils.OnMultiClickListener
import siau.android.base.SBApplication
import siau.android.http.model.FriendModel

class FriendListAdapter(val context: Context, list: ArrayList<FriendModel>, var listener: OnMultiClickListener, var deleteListener: OnMultiClickListener, var giveListener: OnMultiClickListener) : HBaseAdapter<FriendListViewHolder, FriendModel>(list) {
    override fun bindData(holder: FriendListViewHolder, bean: FriendModel, position: Int) {
        holder.tvName.text = when (bean.identityType) {
            1 -> {
                "妈妈"
            }
            2 -> {
                "爸爸"
            }
            else -> {
                bean.userIdentity
            }
        }
        if (bean.isMe == 1) {
            holder.tvTip.visibility = View.VISIBLE
        } else {
            holder.tvTip.visibility = View.GONE
        }
        if (!TextUtils.isEmpty(bean.avatarUrl)) {
            GlideUtils.loadCircleImage(context, bean.avatarUrl, holder.iv, R.drawable.oval_white, R.drawable.oval_white)
        } else {
            holder.iv.setImageResource(R.drawable.oval_white)
        }
        if (bean.select) {
            holder.tvName.setTextColor(ContextCompat.getColor(context, R.color.white))
            holder.itemView.setBackgroundResource(R.drawable.rectangle_circle_friend_list_select)
            holder.x.visibility = View.VISIBLE
            holder.give.visibility = View.VISIBLE
            holder.x.setOnClickListener {
                it.tag = bean
                deleteListener.onMultiClick(it)
            }
            holder.give.setOnClickListener {
                it.tag = bean
                giveListener.onMultiClick(it)
            }
        } else {
            holder.tvName.setTextColor(ContextCompat.getColor(context, R.color.color_777777))
            holder.itemView.setBackgroundResource(R.drawable.rectangle_circle_friend_list)
            holder.x.visibility = View.GONE
            holder.give.visibility = View.GONE
            holder.x.setOnClickListener {}
            holder.give.setOnClickListener {}
        }
        if (SBApplication.userData.isCreator == 1 && bean.isMe == 0) {
            holder.itemView.setOnClickListener {
                it.tag = position
                listener.onMultiClick(it)
            }
        } else {
            holder.itemView.setOnClickListener { }
        }
    }

    override fun bindView(parent: ViewGroup, viewType: Int): FriendListViewHolder {
        val v = LayoutInflater.from(parent.context).inflate(R.layout.item_friend_list, parent, false)
        return FriendListViewHolder(v)
    }
}